package com.fairytask.ui
{
	import com.fairytask.data.Modulator;
	import com.fairytask.engine.components.button.Button;
	import com.fairytask.engine.components.group.ViewGroup;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.resource.StaticIni;
	import com.fairytask.ui.base.FrameUI;
	
	import flash.events.MouseEvent;

	public class ArenaShopUI extends FrameUI
	{
		public static var _self:ArenaShopUI;
		private var _model                   :Modulator = Modulator.instance;
		public var shoppingList    :ViewGroup;
		public var shopNameLab     :Label;
		public var proPage         :Button;
		public var nextPage        :Button;
		public var score           :Label;
		public var pScore          :Label;
		public var info            :Label;
		public var pageNum         :Label;
		private var currPage       :int;
		private var _totalPage     :int;
		private var goodsInfo      :Object;	
		private var _bindArr       :Array=[];
		private var _pScore        :int;

		public function ArenaShopUI()
		{
			initEvent();
			init();
			initProp();
		}
		//获取服务器端数据
		/*public function getGoods(e:CustomToClientEvent):void
		{
			goodsInfo =  com.adobe.serialization.json.JSON.decode(e.pList[1]);
			currPage = goodsInfo.page+1; 
			_totalPage=goodsInfo.totalpage;
			showcurrPage();
		}*/
		public static function getInstance():ArenaShopUI
		{
			if(_self==null)
			{
				_self=new ArenaShopUI();
			}
			return _self;
		}
		override public function hide(e:*=null):void
		{
			super.hide(e);
		}
		private function initProp():void
		{
			//bindManager.BindViewProp(model.scene.GetView(ViewDefine.VIEWPORT_PACKAGE),"Score",getCapital);
		}
		private function getCapital(key:String,val:int):void
		{
			_pScore=val;
			pScore.htmlStrByBorder=_pScore.toString();
			for(var i:int=0;i<_bindArr.length;i++)
			{
				if(null != _bindArr[i])
				{
					ShopGoodsUI(_bindArr[i]).haveMoney = _pScore;
				}
			}
		}
		private function init():void
		{
			//proPage.mouseEnabled = false;
		}
		//初始化事件
		private function initEvent():void
		{
			//_model.addEventListener(CustomToClientEvent.SERVER_CUSTOMMSG_SELL_ARENA,getGoods);
			proPage.addEventListener(MouseEvent.CLICK,onProPage);
			nextPage.addEventListener(MouseEvent.CLICK,onNextPage);
		}
		//上一页显示
		private function onProPage(e:MouseEvent):void
		{
			if(currPage>1)
			{
				//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_ARENA_SHOP,currPage-2);
			}
		}
		//下一页显示
		private function onNextPage(e:MouseEvent):void
		{
			if(currPage<_totalPage)
			{
				//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_ARENA_SHOP,currPage);
			}
		}
		//显示当前页数据
		private function showcurrPage():void
		{
			proPage.mouseEnabled  = currPage!=1;
			nextPage.mouseEnabled = currPage!=_totalPage;
			pageNum.htmlStrByBorder=currPage+"/"+_totalPage;
			//清空数据
			for(var j:int=0;j<9;j++)
			{
				shoppingList.getItemByIndex(j).clear();
				shoppingList.getItemByIndex(j).visible=false;
			}
			//添加每个数据
			for(var i:int=0;i<goodsInfo.goods.length;i++)
			{
				shoppingList.getItemByIndex(i).visible=true;
				var gItem:ShopGoodsUI = new ShopGoodsUI(goodsInfo.goods[i],_pScore,true);
				gItem.goodNum.visible = gItem.numClip.visible = false;
				gItem.x=4;
				gItem.y=6;
				gItem.BuyBtn.label=StaticIni.getSwfLangStr("1000000134");
				_bindArr[i] = gItem;
				shoppingList.getItemByIndex(i).addItem(_bindArr[i]);
			}
		}
	}
}